Always generate a lockfile with dev-dependencies
authorAlex Crichton <alex@alexcrichton.com>
Sun, 17 Aug 2014 05:38:32 +0000 (22:38 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 17 Aug 2014 05:38:32 +0000 (22:38 -0700)
Previously an invocation of `cargo build` would generate a lockfile *without*
dev dependencies, but an invocation of `cargo test` would generate a lockfile
*with* dependencies. This causes odd problems and diffs with the lockfile.

This commit switches the resolve-to-be-a-lockfile to using all dependencies of a
package, while the resolve-to-be-compiled continues to use just the dependencies
needed for the current build.

src/cargo/ops/cargo_compile.rs
tests/test_cargo_compile_git_deps.rs

index 105ad094371feb66df5f2e40de3e8fe79fa15ec7..d7c44c19efbc22ed5aab4a2eabbda8e378ac62e9 100644 (file)
@@ -91,7 +91,7 @@ pub fn compile(manifest_path: &Path,
         }
 
         let resolved = try!(resolver::resolve(package.get_package_id(),
-                                              dependencies.as_slice(),
+                                              package.get_dependencies(),
                                               &mut registry));
 
         try!(registry.add_overrides(override_ids));
index 4a857aea0f2cf717b1be56f8a71fe4a6bb9888f7..1523f2344873fca3190514928abac04f5e26ec34 100644 (file)
@@ -952,3 +952,62 @@ test!(dep_with_changed_submodule {
                 .with_stderr("")
                 .with_status(0));
 })
+
+test!(dev_deps_with_testing {
+    let p2 = git_repo("bar", |project| {
+        project.file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+        "#)
+        .file("src/lib.rs", r#"
+            pub fn gimme() -> &'static str { "zoidberg" }
+        "#)
+    }).assert();
+
+    let p = project("foo")
+        .file("Cargo.toml", format!(r#"
+            [project]
+
+            name = "foo"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dev-dependencies.bar]
+            version = "0.5.0"
+            git = '{}'
+        "#, p2.url()).as_slice())
+        .file("src/main.rs", r#"
+            fn main() {}
+
+            #[cfg(test)]
+            mod tests {
+                extern crate bar;
+                #[test] fn foo() { bar::gimme(); }
+            }
+        "#);
+
+    // Generate a lockfile which did not use `bar` to compile, but had to update
+    // `bar` to generate the lockfile
+    assert_that(p.cargo_process("cargo-build"),
+        execs().with_stdout(format!("\
+{updating} git repository `{bar}`
+{compiling} foo v0.5.0 ({url})
+", updating = UPDATING, compiling = COMPILING, url = p.url(), bar = p2.url())));
+
+    // Make sure we use the previous resolution of `bar` instead of updating it
+    // a second time.
+    assert_that(p.process(cargo_dir().join("cargo-test")),
+        execs().with_stdout(format!("\
+{compiling} bar v0.5.0 ({bar}#[..])
+{compiling} foo v0.5.0 ({url})
+{running} target[..]test[..]foo-[..]
+
+running 1 test
+test tests::foo ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+", compiling = COMPILING, url = p.url(), running = RUNNING, bar = p2.url())));
+})